<!--
* @description 账号管理
* @fileName userList.vue
* @author huangyu
* @date 2023/02/15 09:19:35
!-->
<template>
    <div>
        <el-form :inline="true" class="otor_form otor_form_search">
            <el-form-item label="游戏名称">
                <el-input placeholder="游戏名称" v-model="gameName"></el-input>
            </el-form-item>
            <el-form-item label="账号">
                <el-input placeholder="账号" v-model="gameCode"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="getData">查询</el-button>
            </el-form-item>
            <el-form-item style="margin-left:100px;">
                <el-button type="primary"><router-link :to="'/game/zx/userRealAdd'" style="color:#fff;">账号申请</router-link></el-button>
                <el-button type="primary"><router-link :to="'/game/zx/userReal'" style="color:#fff;">账号申请列表</router-link></el-button>
            </el-form-item>
        </el-form>
        <el-table :data="userList" border>
            <el-table-column type="index" width="50" label="序号"></el-table-column>
            <el-table-column label="诛仙游戏" prop="gameId">
                <template slot-scope="scope">
                    {{scope.row.gameId==1?"东方诛仙":""}}
                </template>
            </el-table-column>
            <el-table-column label="游戏名称" prop="gameName"></el-table-column>
            <el-table-column label="账号" prop="gameCode"></el-table-column>
            <el-table-column label="qq" prop="qq"></el-table-column>
            <el-table-column label="角色配置">
                <template slot-scope="scope">
                    <el-checkbox-group v-model="scope.row.powerInfo.roleInfo" @change="changePowerRole(scope.row)">
                        <el-checkbox label="管理员"></el-checkbox>
                        <el-checkbox label="GM"></el-checkbox>
                        <el-checkbox label="cian"></el-checkbox>
                        <el-checkbox label="bbs"></el-checkbox>
                    </el-checkbox-group>
                </template>
            </el-table-column>
            <el-table-column label="状态">
                <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.status" @change="changePowerRole(scope.row)">
                        <el-radio :label="1">正常</el-radio>
                        <el-radio :label="-1">禁止</el-radio>
                        <el-radio :label="2">到期</el-radio>
                    </el-radio-group>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import { get } from '@/common/app.js'
export default {
    components: {},
    data() {
        return {
            userList: [],
            gameName: "",
            gameCode: "",
        }
    },
    mounted() {
        this.getData()
    },
    methods: {
        // 更新数据
        changePowerRole(row){
            let params = {
                type: 'getUser',
                api: 'api-user-update',
                data: {
                    _id: row._id,
                    roleInfo: row.powerInfo.roleInfo,
                    status: row.status,
                },
            }
            get('game', params).then(res => {
                if (res) {
                    console.log(res)
                    if(res.type=='error'){
                        this.$message.error(res.msg)
                    }
                }
            })
        },
        getData(){
            let params = {
                type: 'getUser',
                api: 'api-user-list',
                data: {
                    gameName: this.gameName,
                    gameCode: this.gameCode,
                },
            }
            get('game', params).then(res => {
                if (res) {
                    // console.log(res.data)
                    this.userList = res.data
                }
            })
        },
    },
}
</script>

<style scoped>

</style>